//
//  BDTabBarController.m
//  BeidouMall
//
//  Created by qie on 16/3/28.
//  Copyright © 2016年 qie. All rights reserved.
//

#import "BDTabBarController.h"
#import "BDHomeViewController.h"
#import "BDSettingTableViewController.h"
#import "BDNavigationController.h"
#import "BDTypeViewController.h"
#import "BDBeidouViewController.h"
#import "BDJianHuoHomeViewController.h"

@interface BDTabBarController () <ZTTabbarDelegate>

@end

@implementation BDTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
    BDHomeViewController *home = [stroyboard instantiateViewControllerWithIdentifier:@"HomeStoryboardID"];
    BDTypeViewController *type = [stroyboard instantiateViewControllerWithIdentifier:@"TypeStoryboardID"];
    BDBeidouViewController *beidou = [stroyboard instantiateViewControllerWithIdentifier:@"BeidouStoryboardID"];
    BDSettingTableViewController *setting = [stroyboard instantiateViewControllerWithIdentifier:@"SettingStoryboardID"];
    BDJianHuoHomeViewController *jianhuo = [stroyboard instantiateViewControllerWithIdentifier:@"JianHuoStoryboardID"];
    
    [self addChildVc:home image:@"homeBtn" selectImage:@"homeBtn_s" title:NSLocalizedString(@"home", @"")];
    [self addChildVc:jianhuo image:@"JianhuoBtn" selectImage:@"JianhuoBtn_s"  title:NSLocalizedString(@"jianhuo", @"")];
    [self addChildVc:type image:@"typeBtn" selectImage:@"typeBtn_s"  title:NSLocalizedString(@"type", @"")];
    [self addChildVc:beidou image:@"shopcartBtn" selectImage:@"shopcartBtn_s" title:NSLocalizedString(@"beidou", @"")];
    [self addChildVc:setting image:@"myBtn" selectImage:@"myBtn_s"  title:NSLocalizedString(@"my", @"")];
    
    UIImageView *tabBarBg = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                                           0,
                                                                                           self.tabBar.frame.size.width,
                                                                                           self.tabBar.frame.size.height)];
    tabBarBg.image = [[UIImage imageNamed:@"tabbar_bg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.tabBar insertSubview:tabBarBg atIndex:0];
    
    UIView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                0,
                                                                self.tabBar.frame.size.width,
                                                                1)];
    line.backgroundColor = RGBColor(187, 187, 187);
    [self.tabBar insertSubview:line atIndex:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)addChildVc:(UIViewController *)childVC image:(NSString *)image selectImage:(NSString *)selectImage title:(NSString *)title {
    if ([title isEqualToString:@"背兜"]) {
        childVC.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 2, 0, -2);
    }
    childVC.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVC.tabBarItem.title = title;
    UIFont *font;
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        font = [UIFont fontWithName:@"Bzdbt" size:8.0];
    } else {
        font = [UIFont boldSystemFontOfSize:12.0];
    }
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       font,NSFontAttributeName,
                                                       RGBColor(102, 102, 102),NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       RGBColor(109, 38, 25), NSForegroundColorAttributeName,
                                                       nil] forState:UIControlStateSelected];
    
    BDNavigationController *nav = [[BDNavigationController alloc] initWithRootViewController:childVC];
    [self addChildViewController:nav];
}

#pragma mark ZTTabBarDelegate

- (void)tabBarDidClickCenterButton:(ZTTabBar *)tabbar {
    NSLog(@"中间button点击事件");
}

@end
